package hhm.android.my

import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import siau.android.base.SBApplication
import siau.android.base.SBBaseActivity
import siau.android.base.ZxingUtils

class ScanInviteActivity : SBBaseActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setTitleMainColorAndTextBlank()
        setContentView(R.layout.activity_scan_invite)
        initTitle(getString(R.string.face_to_face_invite))

        val dm = applicationContext.resources.displayMetrics
        val screenWidth = dm.widthPixels

        val ivBg: ImageView = findViewById(R.id.activity_scan_invite_bottom_bg)
        val layoutParams = ivBg.layoutParams
        layoutParams.width = screenWidth
        layoutParams.height = screenWidth
        ivBg.layoutParams = layoutParams
        ivBg.setImageResource(R.mipmap.invite_bottom_bg)

        val iv: ImageView = findViewById(R.id.activity_scan_invite_iv)
        val tip: TextView = findViewById(R.id.activity_scan_invite_tip)
        val qrCode = ZxingUtils.createQRCode(SBApplication.userData.inviteUrl, dp2px(235f))
//        Glide.with(this).load(qrCode).into(iv)
        iv.setImageBitmap(qrCode)

        var s: String = when (SBApplication.userData.identityType) {
            1 -> {
                getString(R.string.mother)
            }
            2 -> {
                getString(R.string.father)
            }
            else -> {
                SBApplication.userData.userIdentity
            }
        }
        tip.text = getString(R.string.scan_invite_tip_2) + s + getString(R.string.scan_invite_tip_3)
    }
}